package com.sibco.client.common;
import com.bstek.dorado.data.db.dialect.OracleDialect;

public class MyOracleDialect extends OracleDialect {
	public String getPagingSql(String sql, int pageSize, int pageIndex){
        int offset = pageSize * (pageIndex - 1);
        boolean hasOffset = pageIndex > 1;
        StringBuffer pagingSelect = new StringBuffer(sql.length() + 100);
        if(hasOffset)
            pagingSelect.append("SELECT * FROM ( SELECT row_.*, rownum rownum_ FROM ( ");
        else
        	pagingSelect.append("SELECT * FROM ( SELECT row_.*, rownum rownum_ FROM ( ");
        	//pagingSelect.append("SELECT * FROM ( ");
        pagingSelect.append(sql);
        if(hasOffset)
            pagingSelect.append(" ) row_ WHERE rownum <= " + (offset + pageSize) + ") WHERE " + "rownum_" + " > " + offset);
        else
        	pagingSelect.append(" ) row_ WHERE rownum <= " + (offset + pageSize) + ") WHERE " + "rownum_" + " >0 ");
            //pagingSelect.append(" ) WHERE rownum <= " + pageSize);
        return pagingSelect.toString();
    }
}
